//
//  NoticeRepeatViewController.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/8/17.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "NoticeRepeatViewController.h"

@interface NoticeRepeatViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
}
@property(nonatomic,weak)IBOutlet UITableView *mainTableView;
@property(nonatomic,strong)NSMutableArray *weekdays;
@end

@implementation NoticeRepeatViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"重复";
    [self configTableView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    if ([self.weekdaysFromSetting count]>0) {
        [self.weekdays addObjectsFromArray:self.weekdaysFromSetting];
    }
    [self.mainTableView reloadData];
}
-(void)configTableView{
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    self.mainTableView.tableFooterView = [UIView new];
    self.mainTableView.layer.cornerRadius = 10;
    self.mainTableView.clipsToBounds = YES;
}
- (void)leftbuttonPressed:(id)sender{
    if (self.block) {
        self.block(self.weekdays);
    }
    [self.rt_navigationController popViewControllerAnimated:YES complete:nil];
}
#pragma mark - tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 7;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    switch (indexPath.row) {
        case 0:
        {
            cell.textLabel.text = @"周一";
        }
            break;
        case 1:
        {
            cell.textLabel.text = @"周二";
        }
            break;
        case 2:
        {
            cell.textLabel.text = @"周三";
        }
            break;
        case 3:
        {
            cell.textLabel.text = @"周四";
        }
            break;
        case 4:
        {
            cell.textLabel.text = @"周五";
        }
            break;
        case 5:
        {
            cell.textLabel.text = @"周六";
        }
            break;
        case 6:
        {
            cell.textLabel.text = @"周日";
        }
            break;
        default:
            break;
    }
    if ([self.weekdays containsObject:cell.textLabel.text]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if ([self.weekdays containsObject:cell.textLabel.text]) {
        [self.weekdays removeObject:cell.textLabel.text];
    }else {
        [self.weekdays addObject:cell.textLabel.text];
    }
    [self.mainTableView reloadData];
}
- (NSMutableArray *)weekdays {
    if (!_weekdays) {
        _weekdays = [NSMutableArray array];
    }
    return _weekdays;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
